package com.tsd.system.service.impl;

import com.tsd.core.utils.HlpUtils;
import com.tsd.core.vo.PageBean;
import com.tsd.service.BaseServiceImpl;
import com.tsd.system.dao.SysUserGroupMapper;
import com.tsd.system.entity.SysUser;
import com.tsd.system.entity.SysUserGroup;
import com.tsd.system.service.SysUserGroupService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 描述：SysUserGroup 服务实现层
 *
 * @author Hillpool
 * @date 2019/03/12 12:20:51
 */
@Service
public class SysUserGroupServiceImpl extends BaseServiceImpl implements SysUserGroupService {

    @Resource
    private SysUserGroupMapper sysUserGroupMapper;

    @Override
    public SysUserGroup getSysUserGroupById(Long id) throws Exception {
        return sysUserGroupMapper.selectByPrimaryKey(id);
    }

    @Override
    public void saveSysUserGroup(SysUserGroup record, SysUser sysUser) throws Exception {
        if (HlpUtils.isEmpty(record.getId())) {
            super.autoInjectBaseData(record, sysUser, TYPE_CREATE);
            sysUserGroupMapper.insertSelective(record);
        } else {
            super.autoInjectBaseData(record, sysUser, TYPE_UPDATE);
            sysUserGroupMapper.updateByPrimaryKeySelective(record);
        }
    }

    @Override
    public void deleteSysUserGroup(Long id, SysUser sysUser) throws Exception {
        sysUserGroupMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<SysUserGroup> findSysUserGroups(Map<String, Object> params, PageBean page) throws Exception {
        return sysUserGroupMapper.selectByPage(params, page);
    }
}
